package com.ruben.simplescaffold.controller.rest;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruben.simplescaffold.entity.UserDetail;
import com.ruben.simplescaffold.pojo.common.Result;
import com.ruben.simplescaffold.pojo.dto.CommonDTO;

/**
 * 测试控制层
 *
 * @author <achao1441470436@gmail.com>
 * @since 2021/8/7 22:58
 */
@RestController
@RequestMapping("test")
public class TestController {


    @Resource
    private HttpServletResponse response;

    @PostMapping
    public Result testBody(@RequestBody CommonDTO commonDTO) {
        return Result.ok().data(commonDTO);
    }

    @GetMapping
    public Result testQueryParam(CommonDTO commonDTO) {
        final UserDetail userDetail = UserDetail.builder().build();
        response.setHeader("set-cookie", "cookie-name=cookie-value; Path=/; HttpOnly; Max-Age=5");
        return Result.ok().data(Arrays.asList(userDetail, userDetail, userDetail));
    }

    @GetMapping("{path}")
    public Result testPath(@PathVariable String path) {
        return Result.ok().data(path);
    }

}
